package threecard.android;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.app.AlertDialog;

public class MainActivity extends Activity {
	public static final String GAME_PREFERENCES = "GamePrefs";
    public static final String GAME_PREFERENCES_EMAIL = "Email"; // String
    public static final String GAME_PREFERENCES_USERNAME = "Username"; // String
    public static final String GAME_PREFERENCES_PASSWORD = "Password"; // String
    public static final String GAME_PREFERENCES_TOKEN = "Token"; // String

    public static final String DEBUG_TAG = "3Cards Log";
    
    protected boolean isEmailAddress(String emailAddress) {
		if (emailAddress == null) return false;
	    String  expression="^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";  
	    CharSequence inputStr = emailAddress;  
	    Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);  
	    Matcher matcher = pattern.matcher(inputStr);  
	    return matcher.matches(); 
	}
    
    /** A md5 code from the internet !*/
	protected String md5(String pass) {
		  MessageDigest digest;
	        try {
	            digest = MessageDigest.getInstance("MD5");
	            digest.reset();        
	            digest.update(pass.getBytes());
	            byte[] a = digest.digest();
	            int len = a.length;
	            StringBuilder sb = new StringBuilder(len << 1);
	            for (int i = 0; i < len; i++) {
	                sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16));
	                sb.append(Character.forDigit(a[i] & 0x0f, 16));
	            }
	            return sb.toString();
	        } catch (NoSuchAlgorithmException e) { e.printStackTrace(); }
	        return null;
	}

	protected void createDialog(String title, String text) {
		AlertDialog ad = new AlertDialog.Builder(this)
				.setPositiveButton("Ok", null).setTitle(title).setMessage(text)
				.create();

		ad.show();
	}
}
